package com.bmc.ccproblem;

/**
 * In graph terminology it is an weighted edge
 */
public class Cable {
    private final DataPoint a;
    private final DataPoint b;
    private final double delay;

    public Cable(DataPoint a, DataPoint b, double delay) {
        this.a = a;
        this.b = b;
        this.delay = delay;
    }

    public double delay() {
        return delay;
    }

    public DataPoint either() {
        return a;
    }

    public DataPoint other() {
        return b;
    }

    public DataPoint other(DataPoint dataPoint) {
        if (dataPoint.equals(a))
            return b;
        else if (dataPoint.equals(b))
            return a;
        else
            throw new IllegalStateException("Inconsistent data point: "
                    + dataPoint);
    }

    @Override
    public String toString() {
        return String.format("%s-%s %.1f", a, b, delay);
    }
}
